<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>seo search</title>
    <style>
      .bc{color:#172B02}
      .bced{color:#D10909}
      .nextpage { color: #FF00CC}
    </style>
    <script type="text/javascript" src="js/jquery1.7.js"></script>
    <script type="text/javascript">
    $(function(){
        $("#btnGo").click(do_click);
        $("#btnGo").click();
    });
    
    var count = 0;
    function do_click(){
        var keyword = $("#keyword").val();
        var website = $("#website").val();
        var url = $("#searchenginee").val();

        count = 0;
        $("#status").empty();
        $("#content").empty();
        url += encodeURIComponent(keyword);
        doWork(url, keyword, website);
    }

    function doWork(url, keyword, website) {
        var msg = "url:(" + url + ")   keyword:(" + keyword + ")    website:" + website; 
        var tmp;
        var param = {url:url};

        $("#status").prepend("<p class='nextpage'>第" + ++count + "页");
        $("#status").prepend("<p class='bc'>" + msg + "</p>");       
        $.post("seo.php", param, 
            function(data){
              $(data).find("span.g").each(function(i) {
              tmp = data;
              var ws = $(this).text();
              if(ws.indexOf(website) != -1) {
                var link = $(this).parent().siblings("h3").children("a").prop("href");

                var msg_click = ("click this url:<a href='" + link + "' target='_blank'>"  + link + "</a>");
                $("#status").prepend("<p class='bced'>" + msg_click + "</p>");
                param.url = link;
                $("#content").load("seo.php", param);
              }
              }).error( function (){
                  $("status").prepend("<p> post error </p>");
                });
         // the next page. 
          $(tmp).find("a.n").each(function(i){
              var title = $(this).text();
              if(title.indexOf("下一页") != -1) {
                var nextpage = $(this).prop("href");
                nextpage = nextpage.substring(nextpage.lastIndexOf("/"));
                var host = url.substring(0, url.lastIndexOf("/"));
                host = host + nextpage;
                doWork(host, keyword,website);
              }
            });
          }, "html");
    }

   </script>
  </head>

  <body>
  <div>
    <span>搜索引擎url</span>
    <input type="text" id="searchenginee" value="http://www.baidu.com/s?wd=">
    <span>关键词：</span>
    <input type="text" id="keyword" value="南风网"/>
    <span>你的站点域名</span>
    <input type="text" id="website" value="hh1488.com"/>
    <input type="button" id="btnGo" value="Go" >
  </div>
  <div id="content"></div>
  <div id="status"></div>
  </body>
  
</html>

